capture log close
log using basicdemogstats.txt, text replace

use NATL2005US.AllCnty.basicdemography.dta, clear
foreach y in 2006 2007 2008 2009 2010 2011 2012 2013 {
append using NATL`y'US.AllCnty.basicdemography.dta, nolabel
}
tab dob_yy, mi
desc, fullnames

* Maternal age
tab mager, mi
summ mager

* Fraction of moms < 20 years old
gen mageLT20 = 0
replace mageLT20 = 1 if mager < 20
tab mageLT20, mi

* Fraction of moms > 35 years old
gen mageGT35 = 0
replace mageGT35 = 1 if mager > 35 
tab mageGT35, mi

* Fraction of moms married
tab mar, mi

* Fraction of moms of each race
tab mracerec, mi
tab mracehisp, mi
gen mrace_constructed = 1 if mracehisp == 6
replace mrace_constructed = 2 if mracehisp <= 5
replace mrace_constructed = 3 if mracehisp == 7
replace mrace_constructed = 4 if mracehisp == 8 & mracerec == 4
replace mrace_constructed = 5 if mracehisp == 8 & mracerec == 3
replace mrace_constructed = 6 if mracehisp == 9
label define mrace_constructed 1 "non-Hispanic White" 2 Hispanic 3 "non-Hispanic Black" 4 Asian 5 "American Indian" 6 "Unknown"
label values mrace_constructed mrace_constructed
tab mrace_constructed, mi

* Fraction of moms foreign born
tab mbstate_rec, mi
tab dob_yy if missing(mbstate_rec), mi
tab ostate if missing(mbstate_rec), mi
tab mbstate_rec if ostate == "NY" & dob_yy == 2008, mi
tab mbstate_rec
tab mbstate_rec if dob_yy != 2008, mi

* Fraction of moms at each educational level
/***
foreach y in 2005 2006 2007 2008 2009 2010 2011 2012 2013 {
display ""
display ""
display "`y'"
tab meducA version if dob_yy == `y', mi
tab meducA version if dob_yy == `y', mi nolab
tab umeduc version if dob_yy == `y', mi
tab umeduc version if dob_yy == `y', mi nolab
tab meducS version if dob_yy == `y', mi
tab meducS version if dob_yy == `y', mi nolab
}
***/

gen momed_constructed = .
replace momed_constructed = 1 if meducA < 3  | meducS < 3
replace momed_constructed = 2 if meducA == 3 | meducS == 3
replace momed_constructed = 3 if meducA == 4 | meducA == 5 | meducS == 4
replace momed_constructed = 4 if meducA == 6 | meducA == 7 | meducA == 8 | meducS == 5
replace momed_constructed = 5 if meducA == 9 | meducS == 6
label define momed_constructed 1 "less than hs" 2 "hs" 3 "some college" 4 ">= college" 5 unknown
label values momed_constructed momed_constructed
bysort dob_yy: tab momed_constructed, mi
tab momed_constructed if dob_yy >= 2005 & dob_yy <= 2008, mi
tab momed_constructed if dob_yy >= 2009 & dob_yy <= 2013, mi
tab momed_constructed if dob_yy >= 2009 & dob_yy <= 2013
tab momed_constructed, mi
tab momed_constructed

* Father's age
tab ufagecomb, mi
tab dob_yy if missing(ufagecomb), mi
tab ufagecomb if dob_yy < 2012 & ufagecomb != 99, mi
summ ufagecomb if dob_yy < 2012 & ufagecomb != 99

* Fraction of father's age < 20
gen fageLT20 = .
replace fageLT20 = 1 if dob_yy < 2012 & ufagecomb < 20
replace fageLT20 = 0 if dob_yy < 2012 & ufagecomb >= 20 & ufagecomb < 99
tab fageLT20 if dob_yy < 2012

* Fraction of father's age > 35
gen fageGT35 = .
replace fageGT35 = 1 if dob_yy < 2012 & ufagecomb > 35 & ufagecomb < 99
replace fageGT35 = 0 if dob_yy < 2012 & ufagecomb <= 35
tab fageGT35 if dob_yy < 2012

* Fraction of fathers of each race
tab fracerec, mi
tab fracehisp, mi
gen frace_constructed = 1 if fracehisp == 6
replace frace_constructed = 2 if fracehisp <= 5
replace frace_constructed = 3 if fracehisp == 7
replace frace_constructed = 4 if fracehisp == 8 & fracerec == 4
replace frace_constructed = 5 if fracehisp == 8 & fracerec == 3
replace frace_constructed = 6 if fracehisp == 9 | (fracehisp == 8 & fracerec == 9)
label define frace_constructed 1 "non-Hispanic White" 2 Hispanic 3 "non-Hispanic Black" 4 Asian 5 "American Indian" 6 "Unknown"
label values frace_constructed frace_constructed
tab frace_constructed, mi

* Fraction of fathers foreign born: data not available

* Fraction of fathers at each educational level
gen daded_constructed = .
replace daded_constructed = 1 if feducA < 3 
replace daded_constructed = 2 if feducA == 3 
replace daded_constructed = 3 if feducA == 4 | feducA == 5 
replace daded_constructed = 4 if feducA == 6 | feducA == 7 | feducA == 8
replace daded_constructed = 5 if feducA == 9 
label define daded_constructed 1 "less than hs" 2 "hs" 3 "some college" 4 ">= college" 5 unknown
label values daded_constructed daded_constructed
tab dob_yy feducA, mi
tab feducA daded_constructed, mi
tab daded_constructed if dob_yy == 2009, mi
tab daded_constructed if dob_yy == 2010, mi
tab daded_constructed if dob_yy == 2011, mi
tab daded_constructed if dob_yy == 2012, mi
tab daded_constructed if dob_yy == 2013, mi
tab daded_constructed if dob_yy >= 2009 & dob_yy <=2013, mi

* Fraction first births
tab lbo_rec, mi
tab tbo_rec, mi

* Fraction of singleton births
tab dplural, mi

log close


